<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>上传头像</title>
    <link rel="stylesheet" href="../plugins/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../plugins/bootstrap-datetimepicker/bootstrap-datetimepicker.css">

    <link rel="stylesheet" href="../css/plugins.reset.css">
    <link rel="stylesheet" href="../css/common.css">
    <link rel="stylesheet" href="../css/icon.css">
    <link rel="stylesheet" href="../css/home.css">
    <style>

    </style>
</head>
<body class="loaded bg-gray">
<div class="wrapper">
    <header class="header">
        <div class="logo pull-left">
            <a href="index.html" target="_self" title="首页">
                LOGO
            </a>
        </div>
        <div class="header-signin pull-right">
            <a href="#" id="js-signin-btn">登录</a>
            /
            <a href="#" id="js-signup-btn">注册</a>
        </div>
    </header>
    <div class="content-wrapper">
        <div class="personal-wrapper container">
            <div class="row">
                <div class="personal-sideBar">
                    <div class="avatar">
                        <img src="../images/home-index-bg.png" alt="">
                    </div>
                    <ul>
                        <li><a href="#"><i class="fa fa-user-o"></i>个人信息</a></li>
                        <li><a href="#"><i class="fa fa-book"></i>修改密码</a></li>
                        <li class="active"><a href="#"><i class="fa fa-bell-o"></i>上传头像</a></li>
                        <li><a href="#"><i class="fa fa-desktop"></i>查看成绩</a></li>
                    </ul>
                </div>
                <div class="personal-content">
                    <div class="user-wrapper">
                        <div class="user-wrapper-header cf">
                            <div class="user-related">
                                <a class="name" href="#">书友20171106094000990</a>
                                <span>考试场次<em>3</em></span>
                                <span>通过场次<em>5</em></span>
                            </div>
                            <div class="user-wrapper-btn">
                                <a id="userSettingBtn" href="#" class="btn-userSetting"><i class="fa fa-pencil"></i></a>
                            </div>
                        </div>
                    </div>
                    <div class="user-wrapper-content">
                        <form action="#" id="uploadForm">
                            <div class="file">
                                <input id="file-img" class="hide" type="file" name="avatar">
                                <a href="javascript:" class="button button-blue" id="uploadBtn">选择图片</a>
                            </div>
                            <div class="preview">
                                <p>预览</p>
                                <div class="preview-box">
                                    <div class="box-w">
                                        <div class="preview-3x">
                                            <img src="../images/default-avatar.png">
                                        </div>
                                        <div class="preview-2x">
                                            <img src="../images/default-avatar.png">
                                        </div>
                                        <div class="preview-1x">
                                            <img src="../images/default-avatar.png">
                                        </div>
                                        <span class="text-3">120px*120px</span>
                                        <span class="text-2">80px*80px</span>
                                        <span class="text-1">34px*34px</span>
                                    </div>
                                </div>
                            </div>
                            <div class="suc"><a class="button button-blue" href="#">确定</a></div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <footer class="footer">
        <div class="container">
            <div class="row">
                <div class="site-map">
                    <ul>
                        <li><a href="javascript:">系统简介</a></li>
                        <li><a href="javascript:">广告服务</a></li>
                        <li><a href="javascript:">试用洽谈</a></li>
                        <li><a href="javascript:">网站地图</a></li>
                        <li><a href="javascript:">联系方式</a></li>
                        <li><a href="javascript:">关于我们</a></li>
                    </ul>
                </div>
                <div class="copyright">
                    Copyright © 2017 <a href="javascript:">Gallonce</a> , Inc. All rights reserved.
                </div>
            </div>
        </div>
    </footer>
</div>

<script src="../plugins/jquery/jquery.min.js"></script>
<script src="../plugins/bootstrap/js/bootstrap.min.js"></script>
<script src="../plugins/layui/layui.all.js"></script>
<script src="../plugins/validator/validator.min.js"></script>
<script src="../plugins/sweetalert/sweetalert2.all.min.js"></script>
<script src="../plugins/bootstrap-datetimepicker/bootstrap-datetimepicker.js"></script>
<script src="../plugins/bootstrap-datetimepicker/locales/bootstrap-datetimepicker.zh-CN.js"></script>

<script src="../js/common.js"></script>
<script>
    $(function () {
        // 屏幕缩放监听
        $(window).on('resize', function () {
            $('.personal-content').css('min-height', ($(window).height() - 189) + 'px')
        }).trigger('resize');

        // 获取图片路径
        function fnGetPath (obj) {
            if (obj) {
                //古代浏览器,IE7、8、9
                if (navigator.userAgent.indexOf("MSIE") > 0 && !(navigator.userAgent.indexOf("MSIE 10.0") > 0)) {
                    //IE7、8、9浏览器特殊处理,要先Select一下获取所选的内容,但是选中情况下不能获取所以要执行blur()再获取
                    obj.select();
                    obj.blur();
                    //IE下取得图片的本地路径
                    return document.selection.createRange().text;
                } else {
                    //如果支持files对象表示是现代浏览器
                    if (obj.files) {
                        var objectURL = window.URL.createObjectURL(obj.files[0]);

                        return objectURL;
                    }
                    //基本不可能用到
                    return obj.value;
                }
            }
        }

        $('#uploadBtn').on('click', function () {
            $('#file-img').trigger('click');
        });

        $('#file-img').on('change', function () {
            var that = this,
                src = $(that).val();
            if (src.indexOf(".jpg") > 0 || src.indexOf(".jpeg") > 0 || src.indexOf(".JPG") > 0 || src.indexOf(".JPEG") > 0) {
                $('#uploadForm img').attr('src', fnGetPath(that));
                $('#uploadForm .suc').show();
            } else {
                layer.msg('请上传格式为jpg、jpeg的图片！');
                $(this).val('');
            }
        });
    });
</script>
</body>
</html>